/********************************************************************************
Script name	:aspnet-mvc.Schema
Description	: Create actual DB schema for database
********************************************************************************/


USE $(aspnet-mvc)
GO
PRINT 'Creating schema'
GO
PRINT '-> dbo.UserProfile'
GO
IF OBJECT_ID('UserProfile') IS NULL
BEGIN
	CREATE TABLE [dbo].[UserProfile]
	(
		[UserId] int NOT NULL,
		[UserName] nvarchar(MAX) COLLATE Cyrillic_General_CI_AS NULL,
		CONSTRAINT [PK__UserProf__1788CC4C7F60ED59] PRIMARY KEY CLUSTERED
		(
			[UserId]
		)
	)
END
GO


PRINT '-> dbo.webpages_Membership'
GO
IF OBJECT_ID('webpages_Membership') IS NULL
BEGIN
	CREATE TABLE [dbo].[webpages_Membership]
	(
		[UserId] int NOT NULL,
		[CreateDate] datetime NULL,
		[ConfirmationToken] nvarchar(128) COLLATE Cyrillic_General_CI_AS NULL,
		[IsConfirmed] bit NULL CONSTRAINT DF__webpages___IsCon__08EA5793 DEFAULT(((0))),
		[LastPasswordFailureDate] datetime NULL,
		[PasswordFailuresSinceLastSuccess] int NOT NULL CONSTRAINT DF__webpages___Passw__09DE7BCC DEFAULT(((0))),
		[Password] nvarchar(128) COLLATE Cyrillic_General_CI_AS NOT NULL,
		[PasswordChangedDate] datetime NULL,
		[PasswordSalt] nvarchar(128) COLLATE Cyrillic_General_CI_AS NOT NULL,
		[PasswordVerificationToken] nvarchar(128) COLLATE Cyrillic_General_CI_AS NULL,
		[PasswordVerificationTokenExpirationDate] datetime NULL,
		CONSTRAINT [PK__webpages__1788CC4C07020F21] PRIMARY KEY CLUSTERED
		(
			[UserId]
		)
	)
END
GO


PRINT '-> dbo.webpages_OAuthMembership'
GO
IF OBJECT_ID('webpages_OAuthMembership') IS NULL
BEGIN
	CREATE TABLE [dbo].[webpages_OAuthMembership]
	(
		[Provider] nvarchar(30) COLLATE Cyrillic_General_CI_AS NOT NULL,
		[ProviderUserId] nvarchar(100) COLLATE Cyrillic_General_CI_AS NOT NULL,
		[UserId] int NOT NULL,
		CONSTRAINT [PK__webpages__F53FC0ED03317E3D] PRIMARY KEY CLUSTERED
		(
			[Provider],[ProviderUserId]
		)
	)
END
GO


PRINT '-> dbo.webpages_Roles'
GO
IF OBJECT_ID('webpages_Roles') IS NULL
BEGIN
	CREATE TABLE [dbo].[webpages_Roles]
	(
		[RoleId] int NOT NULL,
		[RoleName] nvarchar(256) COLLATE Cyrillic_General_CI_AS NOT NULL,
		CONSTRAINT [PK__webpages__8AFACE1A0CBAE877] PRIMARY KEY CLUSTERED
		(
			[RoleId]
		)
,
		CONSTRAINT [UQ__webpages__8A2B61600F975522] UNIQUE NONCLUSTERED
		(
			[RoleName]
		)
	)
END
GO


PRINT '-> dbo.webpages_UsersInRoles'
GO
IF OBJECT_ID('webpages_UsersInRoles') IS NULL
BEGIN
	CREATE TABLE [dbo].[webpages_UsersInRoles]
	(
		[UserId] int NOT NULL,
		[RoleId] int NOT NULL,
		CONSTRAINT [PK__webpages__AF2760AD1367E606] PRIMARY KEY CLUSTERED
		(
			[UserId],[RoleId]
		)
	)
END
GO


